namespace BoxPlayer
{
    class T_AV_Packet;       //
    class T_AV_Packet_Queue; //
};

#ifndef T_AV_PACKET_H
#define T_AV_PACKET_H

#include "stable.h"
#include "avcodec/t_avcodec.h"
#include "t_box_context.h"

namespace BoxPlayer
{
    class T_AV_AudioDecodeBuffer
    {
    public:
        T_MemoryAligned decode_array;
        T_MemoryAligned convert_array;
    public:
        explicit T_AV_AudioDecodeBuffer()
        {
            decode_array.resize(((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2), 16);
            convert_array.resize(((AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2), 16);
        }
    };
    class T_AV_Packet : public T_RecursiveAtomicObject
    {
        Q_OBJECT
    protected:
        T_DECLARE_PRIVATE(T_AV_Packet);
    public:
        explicit T_AV_Packet(T_Box_Media *a_media, AVPacket *a_av_packet);
        virtual ~T_AV_Packet();
        T_Box_Media *media();
        bool isEnd();
        bool isKeyFrame();
        bool isDecoded();
        qint64 timing();
        int &frameNo();
        QByteArray decodeAudio(T_AV_AudioDecodeBuffer *a_decode_buff);
        bool decodeVideoToNull(bool a_make_copy = false);
        QImage decodeVideoToQImage(T_AVPicture *a_decode_buff, const QSize &a_size, int a_depth);
    };
    class T_AV_Packet_Queue : public T_SharedPointerQueue<T_AV_Packet>
    {
        Q_OBJECT
    protected:
        T_DECLARE_PRIVATE(T_AV_Packet_Queue);
    public:
        explicit T_AV_Packet_Queue(T_Box_Media *a_media);
        virtual ~T_AV_Packet_Queue();
        bool isComplete();
        virtual void clear();
        virtual void enqueue(QSharedPointer<T_AV_Packet> a_av_packet);
        qint64 maxTiming();
        qint64 endlessDuration(qint64 a_now_msec);
        qint64 decodedCount(qint64 a_max);
    };
};

#endif // T_AV_PACKET_H
